package cloud.keveri.gateway.core;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

/**
 * 替换 WebHandler
 * <p>
 * 作者：沈自在
 **/
@Component
public class WebHandlerCoverAssist implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(@NonNull BeanDefinitionRegistry registry) throws BeansException {
        final String webHandler = "webHandler";
        final String engineHandler = "engineHandler";
        if (registry.containsBeanDefinition(webHandler) && registry.containsBeanDefinition(engineHandler)) {
            registry.removeBeanDefinition(webHandler);
            registry.registerBeanDefinition(webHandler, registry.getBeanDefinition(engineHandler));
            registry.removeBeanDefinition(engineHandler);
        }
    }

    @Override
    public void postProcessBeanFactory(@NonNull ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
